<template>
  <div>
  </div>
</template>
<script>
import service from "@/api/invoice";
export default {
  created() {
    this.hFiveGetUserInfo();
  },
  methods: {
    async hFiveGetUserInfo() {
      // https://yunqi.dingtalk.com/isv_products_pay_sell_ticket/?corpId=ding4b14d8abe13d9afa35c2f4657eb6378f&appId=17452&activityId=33#/mine
      // 请求数据
      this.$store.state.loading = true;
      const { success = false, data } = await service.hFiveGetUserInfo();
      this.$store.state.loading = false;
      if (!success) {
        return;
      }

      // 获取回掉链接
      let cackBallUrl = this.getUrl("cackBallUrl");
      console.log("cackBallUrl", cackBallUrl);

      if (!cackBallUrl) {
        this.$toast("未获取到回掉链接");
        return;
      }

      // 进行参数转换
      let stringifyData = "";
      Object.keys(data).map(item => {
        stringifyData += `${item}=${data[item]}&`;
      });
      console.log("stringifyData", stringifyData);

      // 链接参数拼接
      cackBallUrl = `${cackBallUrl}?${stringifyData}`;
      window.location.href = cackBallUrl;

      // const url = " https://yunqi.dingtalk.com/isv_products_pay_sell_ticket/?corpId=ding4b14d8abe13d9afa35c2f4657eb6378f&appId=17452&activityId=33&cackBallUrl=https://www.baidu.com/#/mine"

      //       {
      //     "success": true,
      //     "errorCode": null,
      //     "errorMsg": null,
      //     "result": {
      //         "data": "HsZBsxx5cigeiiM9Om2LOdPHdjB4RHFojCmpwaazQOpAIX8FmARgzjc29jgeNhhkZQiFROLumPkVp5NAVyH_RQ==",
      //         "sign": "96e3a6a090f150ef327a1547f20ddee0604f5f95",
      //         "ts": 1566876400232
      //     },
      //     "arguments": null
      // }
      console.log(data);
    },
    getUrl(parameter) {
      return (
        decodeURIComponent(
          (new RegExp("[?|&]" + parameter + "=" + "([^&;]+?)(&|#|;|$)").exec(
            location.href
          ) || [, ""])[1].replace(/\+/g, "%20")
        ) || ""
      );
    }
  }
};
</script>